<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con">
            <span>批量编辑人员证书</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>需要修改的字段</label>
                        <div class="layui-input-block">
                            <select class="layui-select" name="fieldname" id="fieldname" lay-filter="fieldname">
                                <option value="">请选择</option>
                                <option value="type">证书分类</option>
                                <option value="form">证书形式</option>
                                <option value="state">证书状态</option>
                                <option value="electron_dt">电子件有效期</option>
                                <option value="inspect_dt">下次年检时间</option>
                                <option value="custodianid">保管人</option>
                                <option value="store_addr">存放地</option>
                            </select>
                            <p class="error" id="fieldname_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-hide field_divss type_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>证书分类</label>
                        <div class="layui-input-block">
                            <div id="type"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss form_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>证书形式</label>
                        <div class="layui-input-block">
                            <select class="layui-select form" id="form" name="form" key="1" lay-filter="form"></select>
                            <p class="error" id="form_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss state_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>证书状态</label>
                        <div class="layui-input-block">
                            <select class="layui-select state" name="state" id="state" lay-filter="state"></select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss out_dt_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">注销/转出时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="out_dt" id="out_dt" placeholder="请输入" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss electron_dt_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">电子件有效期</label>
                        <div class="layui-input-block">
                            <input type="text" name="electron_dt" id="electron_dt" placeholder="请选择" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss inspect_dt_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">下次年检时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="inspect_dt" id="inspect_dt" placeholder="请选择" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss custodianid_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">保管人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=custodianid&type=use','770px','490px');"></div>
                                <div class="tanxiannei" id="custodianid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=custodianid&type=use','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="custodianid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide field_divss store_addr_divss">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">存放地</label>
                        <div class="layui-input-block">
                            <div id="store_addr"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>
</form>
<script>
    var param_ids = getQueryVariable('ids');


    layui.use(['laytp','form'], function() {
        var form = layui.form;

        facade.ajax({type: 'get', url: ask_cert_muledit}).done(function(res){
            if (res.code === 2000) {

                var form = res.data.form;
                var form_str = '<option value=""></option>';
                for (var i in form){
                    form_str += '<option value="'+i+'">'+form[i]+'</option>';
                }
                $('.form').html(form_str);

                var state = res.data.state;
                var state_str = '';
                for (var i in state){
                    state_str += '<option value="'+i+'">'+state[i]+'</option>';
                }
                $('.state').html(state_str);

                xmselect_dan('type', res.data.type, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#type").find('xm-select').removeClass('error');
                    }else{
                        $("#type").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('store_addr', res.data.store_addr, '');

                render_from();
            }
        });

        form.on('select(fieldname)', function(data){
            if(data.value == ''){
                $('#fieldname_error').show().text('请选择');
                $('#fieldname_error').parent().find('input').addClass('select_error');
            }else{
                $('#fieldname_error').hide();
                $('#fieldname_error').parent().find('input').removeClass('select_error');


                $(".field_divss").addClass('layui-hide');
                $("."+data.value+"_divss").removeClass('layui-hide');
                if(data.value == 'state'){
                    if($("#state").val() == 2 || $("#state").val() == 3){
                        $(".out_dt_divss").removeClass('layui-hide');
                    }else{
                        $(".out_dt_divss").addClass('layui-hide');
                    }
                }
            }
            render_from();
            render_date();
        });

        form.on('select(form)', function(data){
            if(data.value == ''){
                $('#form_error').show().text('请选择');
                $('#form_error').parent().find('input').addClass('select_error');
            }else{
                $('#form_error').hide();
                $('#form_error').parent().find('input').removeClass('select_error');
            }
        });
        form.on('select(state)', function(data){
            if(data.value == 2 || data.value == 3){
                $(".out_dt_divss").removeClass('layui-hide');
            }else{
                $(".out_dt_divss").addClass('layui-hide');
            }
            render_from();
            render_date();
        });

        form.on('submit(add)', function(data){
            data.field.custodianid = tan_tags_getvalue('#custodianid', 'user');
            var validRes = $("#commentForm").valid();

            if(data.field.fieldname == ''){
                $('#fieldname_error').show().text('请选择');
                $('#fieldname_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#fieldname_error').hide();
                $('#fieldname_error').parent().find('input').removeClass('select_error');
            }


            if(data.field.fieldname == 'type'){
                if(!data.field.type){
                    $("#type").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#type").find('xm-select').removeClass('error');
                }
            }
            if(data.field.fieldname == 'form'){
                if(data.field.form == ''){
                    $('#form_error').show().text('请选择');
                    $('#form_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#form_error').hide();
                    $('#form_error').parent().find('input').removeClass('select_error');
                }
            }
            if(data.field.fieldname == 'state'){

            }


            if(!validRes){return false;}



            data.field.ids = param_ids;
            facade.ajax({url: ask_cert_muledit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });
</script>
</body>
</html>
